package com.ice.work.moment.facade.user.controller.resource;

import com.honeybee.cloud.framework.base.exception.service.ServiceExceptionBase;
import com.honeybee.cloud.framework.base.exception.service.ServiceExceptionEnum;
import com.honeybee.cloud.framework.common.page.Page;
import com.honeybee.cloud.framework.common.response.ResponseEntity;
import com.ice.work.moment.facade.user.request.PageResourceRequest;
import com.ice.work.moment.facade.user.vo.ResourceVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Description 回退
 * @Author DELL
 * @Create 2018-12-10
 * @Since 1.0.0
 */
@Slf4j
@Component
@SuppressWarnings("all")
public class ResourceHystrixFallbackFactory implements FallbackFactory<IResourceController> {
    @Override
    public IResourceController create(Throwable throwable) {
        log.error("服务调用异常", throwable);
        return new IResourceController() {
            @Override
            public ResponseEntity<Page<ResourceVO>> pageResource(PageResourceRequest request, Long page, Long size) {
                return getInstance();
            }
        };
    }

    private ResponseEntity getInstance() {
        return ResponseEntity.error(ServiceExceptionBase.getInstance(ServiceExceptionEnum.MOMENT_RESOURCE_SERVICE));
    }
}
